package com.ds.infrastructure.audit.client.handler;

import org.springframework.expression.EvaluationContext;
import org.springframework.expression.ExpressionParser;
import org.springframework.expression.spel.standard.SpelExpressionParser;
import org.springframework.expression.spel.support.StandardEvaluationContext;

/**
 * 作用：
 *
 * @author WeiShaoying
 * @date 2020/7/28
 */
public class SpelParser implements Parser {

    private final ExpressionParser parser = new SpelExpressionParser();

    /**
     * 解析表达式
     *
     * @param root
     * @return
     */
    @Override
    public Object parse(Object root, String expression) {
        EvaluationContext context = new StandardEvaluationContext(root);
        //EvaluationContext context = new CacheEvaluationContext(root);
        return parser.parseExpression(expression).getValue(context);
    }
}
